package com.itheima.springbootconfig.controller;

import com.itheima.springbootconfig.domain.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Version: V1.0
 */
@RestController
public class DemoController {

    /**
     * 纯量,常量,数组,对象
     */
    @Value("${name}")
    private String name;
    @Value("${person.name}")
    private String name2;
    @Value("${person.age}")
    private Integer age;
    @Value("${address[0]}")
    private String address;
    @Value("${msg1}")
    private String msg1;
    @Value("${msg2}")
    private String msg2;

    @Autowired
    private Person person;
    @Autowired
    private Environment env;

    @RequestMapping("/demo")
    public String demo(){
        System.out.println(name);
        System.out.println(name2);
        System.out.println(age);
        System.out.println(address);
        System.out.println(msg1);
        System.out.println(msg2);

        System.out.println("-------------------------------");
        System.out.println(env.getProperty("person.name"));
        System.out.println(env.getProperty("address[0]"));
        System.out.println(env.getProperty("name"));
        System.out.println(person);
        return "123";
    }
}
